home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / dom / NodeImpl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  4.6 KB  |  353 lines

  1. package com.ibm.xml.dom;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectOutputStream;
  5. import java.io.Serializable;
  6. import org.w3c.dom.DOMException;
  7. import org.w3c.dom.Document;
  8. import org.w3c.dom.EntityReference;
  9. import org.w3c.dom.NamedNodeMap;
  10. import org.w3c.dom.Node;
  11. import org.w3c.dom.NodeList;
  12.  
  13. public abstract class NodeImpl implements Node, NodeList, Cloneable, Serializable {
  14.    static final long serialVersionUID = 2815829867052120872L;
  15.    public static final short ELEMENT_DEFINITION_NODE = -1;
  16.    protected DocumentImpl ownerDocument;
  17.    protected NodeImpl parentNode;
  18.    protected NodeImpl previousSibling;
  19.    protected NodeImpl nextSibling;
  20.    protected String name;
  21.    protected String value;
  22.    protected boolean readOnly;
  23.    protected Object userData;
  24.    protected NodeImpl firstChild;
  25.    protected NodeImpl lastChild;
  26.    protected transient boolean syncChildren;
  27.    protected transient boolean syncData;
  28.    int changes;
  29.    protected static int[] kidOK = new int[13];
  30.  
  31.    protected NodeImpl(DocumentImpl var1, String var2, String var3) {
  32.       this.ownerDocument = var1 != null ? var1 : (DocumentImpl)this;
  33.       this.name = var2;
  34.       this.value = var3;
  35.    }
  36.  
  37.    public NodeImpl() {
  38.    }
  39.  
  40.    public abstract short getNodeType();
  41.  
  42.    public String getNodeName() {
  43.       if (this.syncData) {
  44.          this.synchronizeData();
  45.       }
  46.  
  47.       return this.name;
  48.    }
  49.  
  50.    public void setNodeValue(String var1) {
  51.       if (this.readOnly) {
  52.          throw new DOMExceptionImpl((short)7, (String)null);
  53.       } else {
  54.          if (this.syncData) {
  55.             this.synchronizeData();
  56.          }
  57.  
  58.          this.value = var1;
  59.       }
  60.    }
  61.  
  62.    public String getNodeValue() {
  63.       if (this.syncData) {
  64.          this.synchronizeData();
  65.       }
  66.  
  67.       return this.value;
  68.    }
  69.  
  70.    public Node appendChild(Node var1) throws DOMException {
  71.       return this.insertBefore(var1, (Node)null);
  72.    }
  73.  
  74.    public Node cloneNode(boolean var1) {
  75.       if (this.syncData) {
  76.          this.synchronizeData();
  77.       }
  78.  
  79.       if (this.syncChildren) {
  80.          this.synchronizeChildren();
  81.       }
  82.  
  83.       NodeImpl var2;
  84.       try {
  85.          var2 = (NodeImpl)this.clone();
  86.       } catch (CloneNotSupportedException var4) {
  87.          return null;
  88.       }
  89.  
  90.       var2.readOnly = false;
  91.       var2.parentNode = null;
  92.       var2.previousSibling = null;
  93.       var2.nextSibling = null;
  94.       var2.firstChild = null;
  95.       var2.lastChild = null;
  96.       if (var1) {
  97.          for(NodeImpl var3 = (NodeImpl)this.getFirstChild(); var3 != null; var3 = (NodeImpl)var3.getNextSibling()) {
  98.             var2.appendChild(var3.cloneNode(true));
  99.          }
  100.       }
  101.  
  102.       return var2;
  103.    }
  104.  
  105.    public Document getOwnerDocument() {
  106.       return this.ownerDocument;
  107.    }
  108.  
  109.    public Node getParentNode() {
  110.       return this.parentNode;
  111.    }
  112.  
  113.    public Node getNextSibling() {
  114.       return this.nextSibling;
  115.    }
  116.  
  117.    public Node getPreviousSibling() {
  118.       return this.previousSibling;
  119.    }
  120.  
  121.    public NamedNodeMap getAttributes() {
  122.       return null;
  123.    }
  124.  
  125.    public boolean hasChildNodes() {
  126.       if (this.syncChildren) {
  127.          this.synchronizeChildren();
  128.       }
  129.  
  130.       return this.firstChild != null;
  131.    }
  132.  
  133.    public NodeList getChildNodes() {
  134.       if (this.syncChildren) {
  135.          this.synchronizeChildren();
  136.       }
  137.  
  138.       return this;
  139.    }
  140.  
  141.    public Node getFirstChild() {
  142.       if (this.syncChildren) {
  143.          this.synchronizeChildren();
  144.       }
  145.  
  146.       return this.firstChild;
  147.    }
  148.  
  149.    public Node getLastChild() {
  150.       if (this.syncChildren) {
  151.          this.synchronizeChildren();
  152.       }
  153.  
  154.       return this.lastChild;
  155.    }
  156.  
  157.    public Node insertBefore(Node var1, Node var2) throws DOMException {
  158.       if (this.readOnly) {
  159.          throw new DOMExceptionImpl((short)7, (String)null);
  160.       } else if (var1 instanceof NodeImpl && (var1.getOwnerDocument() == this.ownerDocument || this.getNodeType() == 9 && var1.getOwnerDocument() == (Document)this)) {
  161.          if (this.syncChildren) {
  162.             this.synchronizeChildren();
  163.          }
  164.  
  165.          NodeImpl var3 = (NodeImpl)var1;
  166.          boolean var4 = true;
  167.  
  168.          for(NodeImpl var5 = this.parentNode; var4 && var5 != null; var5 = var5.parentNode) {
  169.             var4 = var3 != var5;
  170.          }
  171.  
  172.          if (!var4) {
  173.             throw new DOMExceptionImpl((short)3, (String)null);
  174.          } else if (var2 != null && var2.getParentNode() != this) {
  175.             throw new DOMExceptionImpl((short)8, (String)null);
  176.          } else {
  177.             if (var3.getNodeType() == 11) {
  178.                for(Node var6 = var3.getFirstChild(); var6 != null; var6 = var6.getNextSibling()) {
  179.                   if ((kidOK[this.getNodeType()] & 1 << var6.getNodeType()) == 0 && true) {
  180.                      throw new DOMExceptionImpl((short)3, (String)null);
  181.                   }
  182.                }
  183.  
  184.                while(var3.hasChildNodes()) {
  185.                   this.insertBefore(var3.getFirstChild(), var2);
  186.                }
  187.             } else {
  188.                if ((kidOK[this.getNodeType()] & 1 << var3.getNodeType()) == 0 && true) {
  189.                   throw new DOMExceptionImpl((short)3, (String)null);
  190.                }
  191.  
  192.                Node var8 = var3.getParentNode();
  193.                if (var8 != null) {
  194.                   var8.removeChild(var3);
  195.                }
  196.  
  197.                NodeImpl var7 = var2 == null ? this.lastChild : ((NodeImpl)var2).previousSibling;
  198.                var3.parentNode = this;
  199.                var3.previousSibling = var7;
  200.                if (var7 == null) {
  201.                   this.firstChild = var3;
  202.                } else {
  203.                   var7.nextSibling = var3;
  204.                }
  205.  
  206.                var3.nextSibling = (NodeImpl)var2;
  207.                if (var2 == null) {
  208.                   this.lastChild = var3;
  209.                } else {
  210.                   ((NodeImpl)var2).previousSibling = var3;
  211.                }
  212.             }
  213.  
  214.             this.changed();
  215.             return var3;
  216.          }
  217.       } else {
  218.          throw new DOMExceptionImpl((short)4, (String)null);
  219.       }
  220.    }
  221.  
  222.    public Node removeChild(Node var1) throws DOMException {
  223.       if (this.readOnly) {
  224.          throw new DOMExceptionImpl((short)7, (String)null);
  225.       } else if (var1 != null && var1.getParentNode() != this) {
  226.          throw new DOMExceptionImpl((short)8, (String)null);
  227.       } else {
  228.          NodeImpl var2 = (NodeImpl)var1;
  229.          NodeImpl var3 = var2.previousSibling;
  230.          NodeImpl var4 = var2.nextSibling;
  231.          if (var3 != null) {
  232.             var3.nextSibling = var4;
  233.          } else {
  234.             this.firstChild = var4;
  235.          }
  236.  
  237.          if (var4 != null) {
  238.             var4.previousSibling = var3;
  239.          } else {
  240.             this.lastChild = var3;
  241.          }
  242.  
  243.          var2.parentNode = null;
  244.          var2.nextSibling = null;
  245.          var2.previousSibling = null;
  246.          this.changed();
  247.          return var2;
  248.       }
  249.    }
  250.  
  251.    public Node replaceChild(Node var1, Node var2) throws DOMException {
  252.       this.insertBefore(var1, var2);
  253.       return this.removeChild(var2);
  254.    }
  255.  
  256.    public int getLength() {
  257.       int var1 = 0;
  258.  
  259.       for(NodeImpl var2 = this.firstChild; var2 != null; var2 = var2.nextSibling) {
  260.          ++var1;
  261.       }
  262.  
  263.       return var1;
  264.    }
  265.  
  266.    public Node item(int var1) {
  267.       NodeImpl var2 = this.firstChild;
  268.  
  269.       for(int var3 = 0; var3 < var1 && var2 != null; ++var3) {
  270.          var2 = var2.nextSibling;
  271.       }
  272.  
  273.       return var2;
  274.    }
  275.  
  276.    public void setReadOnly(boolean var1, boolean var2) {
  277.       if (this.syncData) {
  278.          this.synchronizeData();
  279.       }
  280.  
  281.       this.readOnly = var1;
  282.       if (var2) {
  283.          if (this.syncChildren) {
  284.             this.synchronizeChildren();
  285.          }
  286.  
  287.          for(NodeImpl var3 = this.firstChild; var3 != null; var3 = var3.nextSibling) {
  288.             if (!(var3 instanceof EntityReference)) {
  289.                var3.setReadOnly(var1, true);
  290.             }
  291.          }
  292.       }
  293.  
  294.    }
  295.  
  296.    public boolean getReadOnly() {
  297.       if (this.syncData) {
  298.          this.synchronizeData();
  299.       }
  300.  
  301.       return this.readOnly;
  302.    }
  303.  
  304.    public void setUserData(Object var1) {
  305.       this.userData = var1;
  306.    }
  307.  
  308.    public Object getUserData() {
  309.       return this.userData;
  310.    }
  311.  
  312.    protected void synchronizeChildren() {
  313.    }
  314.  
  315.    protected void synchronizeData() {
  316.    }
  317.  
  318.    protected void changed() {
  319.       ++this.changes;
  320.       if (this.parentNode != null) {
  321.          this.parentNode.changed();
  322.       }
  323.  
  324.    }
  325.  
  326.    protected static boolean isKidOK(Node var0, Node var1) {
  327.       return (kidOK[var0.getNodeType()] & 1 << var1.getNodeType()) != 0;
  328.    }
  329.  
  330.    public String toString() {
  331.       return "[" + this.getNodeName() + ": " + this.getNodeValue() + "]";
  332.    }
  333.  
  334.    private void writeObject(ObjectOutputStream var1) throws IOException {
  335.       if (this.syncData) {
  336.          this.synchronizeData();
  337.       }
  338.  
  339.       if (this.syncChildren) {
  340.          this.synchronizeChildren();
  341.       }
  342.  
  343.       var1.defaultWriteObject();
  344.    }
  345.  
  346.    static {
  347.       kidOK[9] = 1410;
  348.       kidOK[11] = kidOK[6] = kidOK[5] = kidOK[1] = 442;
  349.       kidOK[2] = 40;
  350.       kidOK[10] = kidOK[7] = kidOK[8] = kidOK[3] = kidOK[4] = kidOK[12] = 0;
  351.    }
  352. }
  353.